//
//  AEHomePageViewModel.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/18.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEHomePageViewModel.h"
#import "AE_Solar-Swift.h"

@implementation AEHomePageViewModel

- (void)initialize {
    [super initialize];
    
    self.title = [AEStringExten localizedValueWithKey:@"首页"];
    
    _groups = [NSMutableArray new];
}


/// 获取新闻分组
/// - Parameter completion: completion description
- (void)requestWithNewsGroups:(RequestCompletionBlock)completion {
    @weakify(self);
    AENewsGroupsRequest *request = [[AENewsGroupsRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            [self.groups removeAllObjects];
            if ([respond.data isKindOfClass:[NSArray class]]) {
                [self.groups addObjectsFromArray:respond.data];
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
